{% load i18n lfs_tags %}

<h2>{% trans 'Data' %}</h2>

<form id="product-data-form"
      action="{% url lfs_manage_edit_product_data product.id %}"
      method="post">

        <fieldset>
            <legend>{% trans "General" %}</legend>
            <div class="field">
                <div class="label">
                    {{ form.active.label_tag }}:
                </div>
                <div>
                    {{ form.active }}
                </div>
            </div>

            <div class="field">
                <div class="label">
                    {% if product.is_variant %}
                        {{ form.active_name }}
                    {% endif %}
                    {{ form.name.label_tag }}:
                </div>

                {% if form.name.errors %}
                    <div class="error">
                        {{ form.name }}
                        {{ form.name.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.name }}
                        {% if product.is_variant %}
                            {{ product.parent.name }}
                        {% endif %}
                    </div>
                {% endif %}
            </div>
        </fieldset>

        <fieldset>
            <legend>{% trans "Urls" %}</legend>

            <div class="field">
                <div class="label">
                    {{ form.slug.label_tag }}:
                </div>

                {% if form.slug.errors %}
                    <div class="error">
                        {{ form.slug }}
                        {{ form.slug.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.slug }}
                        {% if product.is_variant %}
                            {{ product.parent.slug }}
                        {% endif %}
                    </div>
                {% endif %}
            </div>

            <div class="field">
                <div class="label">
                    {% trans "Redirect to" %}
                </div>
                <div>
                    <input type="text"
                           id="redirect_to"
                           name="redirect_to"
                           value="{{ redirect_to }}" />
                </div>
            </div>

        </fieldset>

        <fieldset>
            <legend>{% trans "Article numbers" %}</legend>
            <div class="field">
                <div class="label">
                    {% if product.is_variant %}
                        {{ form.active_sku }}
                    {% endif %}

                    {{ form.sku.label_tag }}:
                </div>

                {% if form.sku.errors %}
                    <div class="error">
                        {{ form.sku }}
                        {{ form.sku.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.sku }}
                        {% if product.is_variant %}
                            {{ product.parent.sku }}
                        {% endif %}
                    </div>
                {% endif %}
            </div>

            <div class="field">
                <div class="label">
                    {{ form.manufacturer.label_tag }}:
                </div>

                {% if form.manufacturer.errors %}
                    <div class="error">
                        {{ form.manufacturer }}
                        {{ form.manufacturer.errors }}
                    </div>
                {% else %}
                    <div>
                        {% if product.is_variant %}
                            {{ product.get_manufacturer|default_if_none:"-" }}
                        {% else %}
                            {{ form.manufacturer }}
                            {% if form.manufacturer.is_hidden %}
                                <input type="text" id="id_manufacturer_autocomplete" value="{{ form.instance.manufacturer.name }}" />
                            {% endif %}
                        {% endif %}
                    </div>
                {% endif %}
            </div>

            <div class="field">
                <div class="label">
                    {{ form.sku_manufacturer.label_tag }}:
                </div>

                {% if form.sku.errors %}
                    <div class="error">
                        {{ form.sku_manufacturer }}
                        {{ form.sku_manufacturer.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.sku_manufacturer }}
                    </div>
                {% endif %}
            </div>
        </fieldset>

        <fieldset>
            <legend>{% trans "Prices" %}</legend>
            <div class="field">
                <div class="label">
                    {% if product.is_variant %}
                        {{ form.active_price }}
                    {% endif %}

                    {{ form.price.label_tag }}:
                </div>

                {% if form.price.errors %}
                    <div class="error">
                        {{ form.price }}
                        {{ form.price.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.price }}
                        {% if product.is_variant %}
                            {{ product.parent.price|currency:request }}
                        {% endif %}
                    </div>
                {% endif %}
            </div>

            {% if not product.is_variant %}
                <div class="field">
                    <div class="label">
                        {{ form.price_unit.label_tag }}:
                    </div>
                    <div>
                        {{ form.price_unit }}
                    </div>
                </div>
            {% endif %}

            {% if not product.is_variant %}
                <div class="field">
                    <div class="label">
                        {{ form.tax.label_tag }}:
                    </div>
                    <div>
                        {{ form.tax }}
                    </div>
                </div>
            {% endif %}

            {% if product.is_configurable_product %}
                <div class="field">
                    <div class="label">
                        {{ form.active_price_calculation }}
                        {{ form.price_calculation.label_tag }}:
                    </div>
                    <div>
                        {{ form.price_calculation }}
                    </div>
                </div>
            {% endif %}

            {% if not product.is_variant %}
                <div class="field">
                    <div class="label">
                        {{ form.price_calculator.label_tag }}:
                    </div>
                    <div>
                        {{ form.price_calculator }}
                    </div>
                </div>
            {% endif %}
            {% if product.is_variant %}
                <div class="field">
                    <div class="label">
                        {{ form.for_sale.label_tag }}:
                    </div>
                    <div>
                        {{ form.active_for_sale }}
                        {% if product.parent.for_sale %}
                            {% trans 'Yes' %}
                        {% else %}
                            {% trans 'No' %}
                        {% endif %}
                    </div>
                </div>
                <div class="field">
                    <div class="label">
                        {{ form.active_for_sale_price }}
                        {{ form.for_sale_price.label_tag }}:
                    </div>
                    <div>
                        {{ form.for_sale_price }}
                        {{ product.parent.for_sale_price|currency:request }}
                    </div>

                </div>
            {% else %}
                <div class="field">

                    <div class="label">
                        {{ form.for_sale }}
                        {{ form.for_sale.label_tag }}:
                    </div>

                    {% if form.for_sale_price.errors %}
                        <div class="error">
                            {{ form.for_sale_price }}
                            {{ form.for_sale_price.errors }}
                        </div>
                    {% else %}
                        <div>
                            {{ form.for_sale_price }}
                        </div>
                    {% endif %}
                </div>
            {% endif %}
        </fieldset>

        {% if not product.is_variant %}
            <fieldset>
                <legend>{% trans "Quantity field" %}</legend>
                <div class="field">
                    <div class="label">
                        {{ form.unit.label_tag }}:
                    </div>
                    <div>
                        {{ form.unit }}
                    </div>
                </div>
                <div class="field">
                    <div class="label">
                        {{ form.type_of_quantity_field.label_tag }}:
                    </div>
                    <div>
                        {{ form.type_of_quantity_field }}
                    </div>
                </div>
            </fieldset>
        {% endif %}

        <fieldset>
            <legend>{% trans "Base price" %}</legend>
            <div class="field">
                <div class="label">
                    {{ form.active_base_price.label_tag }}:
                </div>
                <div>
                    {{ form.active_base_price }}
                    {% if product.is_variant %}
                        {% if product.parent.active_base_price %}
                            {% trans 'Yes' %}
                        {% else %}
                            {% trans 'No' %}
                        {% endif %}
                    {% endif %}
                </div>
            </div>

            <div class="field">
                <div class="label">
                    {{ form.base_price_unit.label_tag }}:
                </div>
                <div>
                    {{ form.base_price_unit }}
                    {% if product.is_variant and product.parent.base_price_unit %}
                        {{ product.parent.base_price_unit }}
                    {% endif %}
                </div>
            </div>

            <div class="field">
                <div class="label">
                    {{ form.base_price_amount.label_tag }}:
                </div>
                <div>
                    {{ form.base_price_amount }}
                    {{ product.parent.base_price_amount }}
                    {{ form.base_price_amount.errors }}
                </div>
            </div>
        </fieldset>

        <div class="field">
            <div class="label">
                {% if product.is_variant %}
                    {{ form.active_short_description }}
                {% endif %}
                {{ form.short_description.label_tag }}:
            </div>

            {% if form.short_description.errors %}
                <div class="error">
                    {{ form.short_description }}
                    {{ form.short_description.errors }}
                </div>
            {% else %}
                <div>
                    {{ form.short_description }}
                </div>
            {% endif %}
        </div>

        <div class="field">
            <div class="label">
                {% if product.is_variant %}
                    {{ form.active_description }}
                {% endif %}
                {{ form.description.label_tag }}:
            </div>

            {% if form.description.errors %}
                <div class="error">
                    {{ form.description }}
                    {{ form.description.errors }}
                </div>
            {% else %}
                <div>
                    {{ form.description }}
                </div>
            {% endif %}
        </div>

        <fieldset>
            <legend>{% trans "Appearance" %}</legend>
            <div class="field">
                <div class="label">
                    {% if product.is_variant %}
                        {{ form.active_static_block }}
                    {% endif %}
                    {{ form.static_block.label_tag }}:
                </div>

                {% if form.static_block.errors %}
                    <div class="error">
                        {{ form.static_block }}
                        {{ form.static_block.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.static_block }}
                    </div>
                {% endif %}
            </div>

            <div class="field">
                <div class="label">
                    {{ form.template.label_tag }}:
                </div>
                {% if form.template.errors %}
                    <div class="error">
                        {{ form.template }}
                        {{ form.template.errors }}
                    </div>
                {% else %}
                    <div>
                        {{ form.template }}
                    </div>
                {% endif %}
            </div>
        </fieldset>
        <div class="buttons">
            <input class="ajax-save-button button"
                   type="submit"
                   value="{% trans 'Save data' %}" />
        </div>
</form>
